$.fn.selectAddress = function(){
	function addData(parent,val){									//添加地区数据
		var Select = document.getElementById(parent)
		var Option = document.createElement('option')
		Option.value = val
		Option.innerHTML = val
		Select.appendChild(Option)
	}
	
	function removeData(parent){										//移除地区数据
		var Select = document.getElementById(parent)
		var Option = document.querySelectorAll('#'+parent+' option')
		for(var index=1;index<Option.length;index++){ 	//第一个option是默认提示选项不能移除，所以index=1
			Select.removeChild(Option[index])
		}
	}
	
	for(var i =0;i<provinceList.length;i++){
		addData('province',provinceList[i].name)
	}
	
	var province = '' 			//被选中的省份
	var city = '' 					// 被选中的城市
	var town = '' 					 //被选中的区域
	var cityItems = ''			 // 被选中省份下的城市选项
	var townItems = ''  		//被选中城市下的区域选项
	
	/*-------点击选择省份下拉框--------*/
	$("#province").click(function(){
		province = ''
		cityItems =''
		if($("#city option").length !=1){											//检查选择城市列表的子元素是否只有第一个			
			removeData("city")
			removeData("town")	
		}
		province = $("#province option:selected").html()  			//获取被被选中的省份
		for(var m=0;m<provinceList.length;m++){ 						//遍历省份
			if(province == provinceList[m].name){
				cityItems = provinceList[m]
				for(var n=0;n<provinceList[m].cityList.length;n++){//遍历添加被选中省份下的城市
					addData("city",provinceList[m].cityList[n].name)
				}
			}
		}
	})
	
	/*-------点击选择城市下拉框--------*/
	$("#city").click(function(){
		city =''
		townItems =''
		if($("#town option").length !=1){								//检查选择区域列表的子元素是否只有第一个		
			removeData("town")
		}
		if(province != ''){															 //判断是否有选择上级地区(省份)操作
			city = $("#city option:selected").html()				 //获取被被选中的城市
			for(var x=0;x<cityItems.cityList.length;x++){ 	//遍历城市
				if(city == cityItems.cityList[x].name){	
					townItems = cityItems.cityList[x].areaList
					for(var y=0;y< townItems.length;y++){		//遍历添加被选中城市下的区域
						addData("town",townItems[y])
					}
				}
			}
		}
	})
	
	/*-------点击选择区域下拉框--------*/
	$("#town").click(function(){
		if(city != ''){																		//判断是否有选择上级地区(城市)操作
			town = $("#town option:selected").html()
			if(province!= '选择省份' && city!="选择城市" && town!='选择区域'){
				console.log('省份/直辖市：'+province+'\n城市:'+city+'\n区/县：'+town)
				return province
			}	
		}
	})
}


var provinceList = [
{name:'二七区', cityList:[		   
{name:'金海商务楼五楼1', areaList:['101','102','103','104','105','106']},
{name:'金海商务五楼2', areaList:['101','102','103','104','105','106']},		   
{name:'金海商务五楼3', areaList:['101','102','103','104','105','106']},
{name:'金海商务五楼4', areaList:['101','102','103','104','105','106']},
]},
{name:'金水区', cityList:[		   
{name:'二七2', areaList:['201','202','203','204','205','206']},		   
]},
{name:'中原区', cityList:[		   
{name:'二七3', areaList:['301','302','303','304','305','306']},		   
]},
{name:'管城区', cityList:[		   
{name:'二七4', areaList:['401','402','403','404','405','406']},		   
]}
];